﻿using System;
using Kiva7.Utilities;
using Kiva7.DataResponse;
using Kiva7.DataClasses;

namespace Kiva7.DataRequests
{
    public class TeamLendersRequest : DataRequest<LendersResponse, Lender>
    {
        public TeamLendersRequest()
            : base(true, true)
        {
        }

        public Uri BuildUri(int teamId, SortBy sortBy)
        {
            UrlCreator url = new UrlCreator(string.Format(BaseUrl + "teams/{0}/lenders.xml", teamId));

            if (sortBy == SortBy.Oldest)
            {
                url.Add("sort_by", "oldest");
            }
            else
            {
                url.Add("sort_by", "newest");
            }

            url.Add("app_id", KivaAppId);

            return url.ToUri();
        }

        public void GetLenders(int teamId, SortBy sortBy)
        {
            LoadResponse(BuildUri(teamId, sortBy));
        }

    }
}
